package experiment_sixth;

public class Teacher extends Person {

    private Course[] cours;
    public Teacher() {
        cours= new Course[1];
    }
    public Teacher(int Id,String Name,String sex){
        this.Id = Id;
        this.Name = Name;
        this.sex = sex;  
        cours = new Course[3];
    }                                                  

    public boolean Selected(Course course){
        boolean cnt=false;
        for(Course c:cours){
            if(c==course){
                cnt=true;
                break;
            }
        }
        return cnt;
    }
    
    public boolean Null(Course course){
        boolean cnt=false;
        for(Course c:cours){
            if(c==null){
                cnt=true;
                break;
            }
        }
        return cnt;
    }
    
    public boolean addCourse(Course course){
        boolean cnt=false;
        if(!Selected(course)&&Null(course)){
            for(int i=0;i<this.cours.length;i++){
                if(cours[i]==null){
                    cours[i]=course;
                    course.addTeacher(this);
                    cnt=true;
                    break;
                }
            }
        }
        return cnt;
    }
    
//    public void displayCourse(){
//        System.out.println("教师：\n"+"ID："+this.Id+"\n姓名："+this.Name+this.sex);
//        for(Course c:cours){
//            if(c!=null){
//                System.out.print("教授课程："+c.getName()+"\n");
//            }
//        }
//        System.out.println();
//    }
    public String toString(){
    	String str0 = "教师：\n"+"ID："+this.Id+"姓名："+this.Name+this.sex+"\n";
    	String str1 = new String();
    	for(Course c:cours){
    		if(c!=null){
    		str1 = "教授课程："+c.getName()+"\n";
    		}
    	}	
    	String str =str0+str1;
		return str;
    }
}
